package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportApiApply;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2019-07-04 19:01:05
 */
@Repository
public class TransportApiApplyDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportApiApplyDao.class);

    public TransportApiApply insert(final TransportApiApply transportApiApply) {
        insert("TransportApiApply.insert", transportApiApply);
        return transportApiApply;
    }

    public Boolean updateInfoById(final TransportApiApply transportApiApply) {
        return update("TransportApiApply.updateInfoById", transportApiApply) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportApiApply.updateInfoByQuery", query) > 0;
    }

    public TransportApiApply selectById(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return queryForObject("TransportApiApply.selectById", query);
    }

    public List<TransportApiApply> selectByQuery(final Query query) {
        return queryForList("TransportApiApply.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportApiApply.countByQuery", query);
    }

    public Boolean deleteById(final Integer id) {
        TransportApiApply transportApiApply = new TransportApiApply();
        transportApiApply.setDeleteFlag(1);
        transportApiApply.setId(id);

        return update("TransportApiApply.updateInfoById", transportApiApply) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportApiApply.deleteById", query) > 0;
    }

    //自动更新调用次数，每次自动+1
    public void updateUseTimes(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        update("TransportApiApply.updateUseTimes", query);
    }
}